﻿namespace BM.Tools.WebControls.MForm.Controls.Helper
{
    using System.Xml;

    internal class NameResolver
    {
        private string localName;

        private string prefix;

        public NameResolver(string fullName, XmlNamespaceManager manager)
        {
            var colonIndex = fullName.IndexOf(":");
            if (colonIndex == -1)
            {
                localName = fullName;
            }
            else
            {
                prefix = fullName.Substring(0, colonIndex);
                localName = fullName.Substring(colonIndex + 1);
            }

            Manager = manager;
        }

        public string FullName
        {
            get;
            private set;
        }

        public XmlNamespaceManager Manager
        {
            get;
            private set;
        }

        public string LocalName
        {
            get
            {
                return localName;
            }
        }

        public string Namespace
        {
            get
            {
                return prefix == null ? Manager.DefaultNamespace : Manager.LookupNamespace(Manager.NameTable.Get(Prefix));
            }
        }

        public string Prefix
        {
            get
            {
                return prefix;
            }
        }
    }
}
